/**
 * Created by thinkl on 2017/6/18.
 */
$(function () {
    var username = '';
    var password = '';
    $('#user_create').click(function () {
        username = $('#username').val();
        password = $('#password').val();
        $.post('/login/create_user', {username: username, password: password}, function (data) {
            var l = JSON.parse(data);
            alert(l.message);
        })
    });
    $('#login').click(function () {
        username = $('#username').val();
        password = $('#password').val();
        $.post('/login/user_login', {username: username, password: password}, function (data) {
            var l = JSON.parse(data);
            if (l.success) {
                location.href = '/static/shopping/shopping.html'
            } else {
                alert(l.message);
            }
        })
    });
    $('#admin_create').click(function () {
        var admin_username = $('#admin_username').val();
        var admin_password = $('#admin_password').val();
        $.post('/login/create_admin', {username: admin_username, password: admin_password}, function (data) {
            var l = JSON.parse(data);
            alert(l.message);

        })
    });
    $('#admin_login').click(function () {
        var admin_username = $('#admin_username').val();
        var admin_password = $('#admin_password').val();
        $.post('/login/user_login', {username: admin_username, password: admin_password}, function (data) {
            var l = JSON.parse(data);
            if (l.success) {
                location.href = '/static/commodity-list/commodity-list.html'
            } else {
                alert(l.message);
            }
        })
    })
});